# %%
import datetime


def getYear(y):
    """
    y = 输入需要跨度的年数
    输入今天日期， 跨度前日期 (固定365一年)
    """
    d = y * 365
    today = datetime.date.today()
    startyear = today - datetime.timedelta(days=d)
    # print(str(startyear))
    return str(startyear), str(today)


def getCal(times, mode="w"):
    """
    mode =
    datetime(2018,6,30).isocalendar()
    输入三个变量进行输出
    """
    timel = times.split("-")
    week = datetime.datetime(
        timel[0], timel[1], timel[2]  # year  # month  # day
    ).isocalendar()[1]
    return week


def ProcessTimeList(starttime, newTimelist, last_time):
    """
    时间列表检测
    返回值位列表
    starttime = 开始时间
    newTimelist = 时间列表
    last = 终止时间
    :: return: TimeList
    """
    if starttime != None and newTimelist != None:
        if starttime in newTimelist:
            newTimelist = newTimelist[newTimelist.index(starttime) :]

        if last_time != None:
            newTimelist = list(set(newTimelist).difference(set(last_time)))
            newTimelist.sort()

        if newTimelist != []:
            if newTimelist[0] < starttime:
                for i in range(14):
                    starttime -= 1
                    if starttime in newTimelist:
                        newTimelist = newTimelist[newTimelist.index(starttime) :]
            return newTimelist
    else:
        return None
